package demo;

import java.util.HashSet;
import java.util.Objects;

//Day08
public class Day18001 {
    public static void main(String[] args) {
        HashSet<Student> set = new HashSet<>();
        set.add(new Student("赵丽颖",18));
        set.add(new Student("范冰冰",20));
        set.add(new Student("杨幂",19));
        set.add(new Student("杨幂",19));

        System.out.println(set);
    }
}

class Student {
    private String name;
    private Integer age;

    public Student() {
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        if(obj == this)
            return true;
        if (obj == null)
            return false;
        if (obj instanceof Student){
            Student s=(Student) obj;
            if(s.getAge()==this.getAge()&&s.getName().equals(this.getName())){
                return true;
            }
            return false;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
